package com.xfg.search.serviceImpl;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.xfg.search.entity.User;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class CreateTokenService {
    public String createToken(User user){
        String token= JWT.create().withAudience(user.getUsername(),user.getPassword())
                .withExpiresAt(new Date(System.currentTimeMillis()+1000*30))//token失效的时间  这里我设置的是30秒失效
                .withNotBefore(new Date())     //token开始生效的时间
                .sign(Algorithm.HMAC256(user.getPassword()));
        return token;
    }
}
